/**
 * Copyright 2014 the original author or authors. All rights reserved.
 */
package com.visionet.security.repository.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.visionet.jumper.core.domain.bean.Page;
import com.visionet.jumper.core.domain.search.Searchable;
import com.visionet.jumper.core.domain.search.SqlSearchable;
import com.visionet.jumper.core.support.jpa.CommonRepository;
import com.visionet.security.repository.SecurityResourceRepository;
import org.springframework.stereotype.Repository;

import com.visionet.security.domain.dto.UrlizedResource;
import com.visionet.security.base.enums.ResourceType;

import javax.annotation.Resource;

/**
 *
 * @author suxiaojing
 * @since 0.0.1
 */
@Repository
public class SecurityResourceRepositoryImpl extends CommonRepository {

	@javax.annotation.Resource
	private SecurityResourceRepository securityResourceRepository;

	public Page getMenuForPage(Page page) {
		Searchable searchable = new SqlSearchable("t_resource", "resource");
		searchable.select("resource.name as name");
		searchable.select("resource.id as id");
		searchable.select("resource.parent_Id as parentId");
		searchable.select("resource.definition as url");
		searchable.select("resource.level as level");
		searchable.select("resource.orderNo as orderNo");
		searchable.eq("resource.type", ResourceType.MENU.toString());
		searchable.eq("resource.isDeleted", false);
		searchable.ascSort("resource.level");
		searchable.ascSort("resource.orderNo");
		searchable.setPage(page);
		return securityResourceRepository.findPageForSpecifyType(searchable, page, UrlizedResource.class);
	}

	public List<Resource> findByTypeAndLevel(ResourceType menu, Integer level) {
		return null;
	}

	public List<Resource> getUrlizedResource(List<ResourceType> typeList) {
		return null;
	}

	public List<UrlizedResource> getUserMenu(String userId) {
		Map<String, Object> params = new HashMap<>();
		params.put("userId", userId);
		params.put("resourceType", ResourceType.MENU.toString());
		return findAll("findUrlizedResourceByUserId", params, UrlizedResource.class);
	}

}
